﻿using Newtonsoft.Json.Linq;

namespace 水下机器人操作系统
{
    public partial class CtrlForm : Form
    {
        public CtrlForm()
        {
            InitializeComponent();
        }

        private void CtrlForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = true;
        }

        private void CtrlForm_Load(object sender, EventArgs e)
        {
            checkListSailMode.SetItemCheckState(1, CheckState.Checked);
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            JObject jObject = new JObject();
            jObject["Output01"] = txtForwardV.Text;
            jObject["Output02"] = txtCourseX.Text;
            jObject["Output03"] = txtCourseY.Text;
            jObject["Output04"] = txtCourseZ.Text;
            jObject["Output05"] = txtVPR.Text;
            jObject["Output06"] = checkSensor1.Checked.ToString();
            jObject["Output07"] = checkSensor2.Checked.ToString();
            jObject["Output08"] = checkSensor3.Checked.ToString();
            string sailModeStr = "";
            if (checkListSailMode.GetItemCheckState(0) == CheckState.Checked)
            {
                sailModeStr = "低功耗";
            }
            else if (checkListSailMode.GetItemCheckState(1) == CheckState.Checked)
            {
                sailModeStr = "常规";
            }
            else if (checkListSailMode.GetItemCheckState(2) == CheckState.Checked)
            {
                sailModeStr = "最大功率";
            }
            jObject["Output09"] = sailModeStr;
            string jsonStr = jObject.ToString();
            Constants.myClient.SendTextPKT(jsonStr);
        }

        private void checkListSailMode_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.Index == 0)
            {
                checkListSailMode.SetItemCheckState(1, CheckState.Unchecked);
                checkListSailMode.SetItemCheckState(2, CheckState.Unchecked);
            }
            else if (e.Index == 1)
            {
                checkListSailMode.SetItemCheckState(0, CheckState.Unchecked);
                checkListSailMode.SetItemCheckState(2, CheckState.Unchecked);
            }
            else if (e.Index == 2)
            {
                checkListSailMode.SetItemCheckState(0, CheckState.Unchecked);
                checkListSailMode.SetItemCheckState(1, CheckState.Unchecked);
            }
        }
    }
}
